﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DynaPrecision.FunctionAnalysis
{
	public class FunctionValueProduct<TFunction, TInput, TResult> : IFunction<TInput, TResult>
		where TFunction : IFunction<TInput, TResult>
	{
		public FunctionValueProduct() { ;}
		public FunctionValueProduct(TFunction function, TResult coefficient)
		{
			WrappedFunction = function;
			this.Coefficient = coefficient;
		}
		TFunction WrappedFunction { get; set; }
		TResult Coefficient { get; set; }
		#region IFunction<TInput,TResult> Members

		public Func<TInput, TResult> Functor
		{
			get { return x => WrappedFunction.Functor(x) * (dynamic)Coefficient; }
		}

		public IFunction<TInput, TResult> Derivative
		{
			get
			{
				return new FunctionValueProduct<IFunction<TInput, TResult>, TInput, TResult>(this.Derivative, this.Coefficient);
			}
		}

		public IFunction<TInput, TResult> Integral
		{
			get
			{
				return new FunctionValueProduct<IFunction<TInput, TResult>, TInput, TResult>(this.Integral, this.Coefficient);
			}
		}

		#endregion
	}
}
